﻿Public Partial Class UserChangePassword
    Inherits BaseUserControl

    Public ReadOnly Property RequestedUsername() As String
        Get
            If Request.QueryString("username") IsNot Nothing Then
                Return Request.QueryString("username").ToString
            Else
                Return ""
            End If
        End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Overrides Sub Rebind()

    End Sub

    Protected Sub btnChangePassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangePassword.Click

        If txtNewPassword.Text.Length = 0 Then
            Me.Prompt("New Password could not be empty!", UserControlPromptTypes.Alert)
            Exit Sub
        End If

        If txtNewPassword.Text <> txtNewPassword1.Text Then
            Me.Prompt("New Password and Confirm New Password is not the same!", UserControlPromptTypes.Alert)
            Exit Sub
        End If

        Try

            Dim membershipUser As MembershipUser = Membership.GetUser(Me.RequestedUsername)
            Dim result As Boolean = membershipUser.ChangePassword(txtOldPassword.Text, txtNewPassword.Text)

            If result Then
                Me.Prompt("Password has been changed successfuly!", UserControlPromptTypes.Successful)
            Else
                Me.Prompt("Old Password is not correct!", UserControlPromptTypes.Alert)
            End If

        Catch ex As Exception

            Me.RaiseError(ex)

        End Try

    End Sub

End Class